package ihakul_client.i_hakul.com.glidedemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    private Button button;
    private String url = "http://cn.bing.com/az/hprichbg/rb/Dongdaemun_ZH-CN10736487148_1920x1080.jpg";
    private String url2 = "http://p1.pstatp.com/large/166200019850062839d3";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.image);
        button = (Button) findViewById(R.id.btn_download);
        loadImage();
    }

    private void loadImage(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //placeholder():在图片加载过程中显示的一张临时图片。
                //diskCacheStrategy():
                Glide.with(MainActivity.this)
                        .load(url2)
//                        .asBitmap()//静态图片
//                        .asGif()//git图片,没有设置时自动判断
                        .placeholder(R.mipmap.ic_launcher)
                        .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用掉Glide的缓存功能
                        .error(R.mipmap.ic_launcher)//异常时显示的图片
                        .override(100,100)//指定图片大小
                        .into(imageView);
            }
        });
    }
}
